package oppsa.view;

import java.util.ArrayList;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import oppsa.controller.Meeting;
import oppsa.controller.MeetingType;
import oppsa.controller.Translate;
import oppsa.model.MeetingDB;
import oppsa.model.MeetingTypeDB;
import oppsa.model.ProjectDB;
import oppsa.util.Session;

public class JTreeMeeting {
	
	private Translate t = new Translate();
	
	public DefaultTreeModel getNode() {
		
		MeetingDB listMeetingDB = new MeetingDB();
		MeetingTypeDB listMeetingType = new MeetingTypeDB();
		listMeetingType.select(Session.userSequence);
		listMeetingDB.select();
		DefaultMutableTreeNode meetingTypeNode = new DefaultMutableTreeNode(t.getLocalizedText("lblMeeting"));
		
		ProjectDB p = new ProjectDB();
		p.select(Session.userSequence);
		//meetingTypeNode.add(new DefaultMutableTreeNode("Default"));//Ajout du noeud default
		
		for (MeetingType meetingType : listMeetingType.getFullList())
		{
			
			DefaultMutableTreeNode nodeMeetingType = new DefaultMutableTreeNode(meetingType.getName());
			meetingTypeNode.add(nodeMeetingType);
			ArrayList<Meeting> listMeeting = new ArrayList<Meeting>();
			listMeeting = listMeetingDB.getMeetingInMeetingType(meetingType.getSequence());
			for (Meeting meeting : listMeeting)
			{
				DefaultMutableTreeNode nodeMeeting = new DefaultMutableTreeNode(meeting.getMeetingName());
				nodeMeetingType.add(nodeMeeting);
			}
		} 

		return new DefaultTreeModel(meetingTypeNode);

	}
}
